package com.itita.weibo.model;

import java.util.List;

import org.apache.commons.httpclient.util.DateUtil;

import weibo4andriod.Comment;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itita.weibo.ui.R;
import com.itita.weibo.util.WeiboUtil;

public class ListCommentAdapter extends BaseAdapter{
   
	private LayoutInflater layoutInflater;
	
	private Context context;
	
	private List<Comment> commentList;
	
	public ListCommentAdapter(LayoutInflater layoutInflater, Context context,
			List<Comment> commentList) {
		this.layoutInflater = layoutInflater;
		this.context = context;
		this.commentList = commentList;
	}
	
	public ListCommentAdapter(Context context,
			List<Comment> commentList) {
		this.context = context;
		this.commentList = commentList;
		this.layoutInflater = LayoutInflater.from(context);
	}
    
	public View getView(int position, View convertView, ViewGroup parent) {
	    ////System.out.println("-------------加载cmtItem----------------");
		View view = layoutInflater.inflate(R.layout.comment_item, null);
		TextView tvItemCmtNickname = (TextView) view.findViewById(R.id.tvItemCmtNickname);
        TextView tvItemCmtDate = (TextView) view.findViewById(R.id.tvItemCmtDate);
		TextView tvItemCmtContent = (TextView) view.findViewById(R.id.tvItemCmtContent);
		
		Comment comment = this.commentList.get(position);
		
		tvItemCmtNickname.setText(comment.getUser().getName());
		tvItemCmtDate.setText(WeiboUtil.getCreateAt(comment.getCreatedAt()));
		tvItemCmtContent.setText(comment.getText());
		
		return view;
	}
    
	public int getCount() {
		return this.commentList.size();
	}

	public Object getItem(int position) {
		return this.commentList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
}
